import Vue from 'vue'
import Router from 'vue-router'
import Auth from '@/components/account/auth'
import Login from '@/components/account/login'
import Home from '@/components/Home/Home' //用户中心
import Customer from '@/components/Customer/Customer' //客户
import register from '@/components/register/register' //到访登记
import addCus from '@/components/addCus/addCus' //新建用户
import editCus from '@/components/addCus/editCus' //新建用户
import Visit from '@/components/Visit/Visit' //回访



Vue.use(Router)

export default new Router({
    routes: [{
        path: '/',
        name: 'Auth',
        component: Auth //钉钉鉴权，空白页面
    }, {
        path: '/Login',
        name: 'Login',
        component: Login
    }, {
        path: '/home',
        name: 'Home',
        component: Home //用户中心
    }, {
        path: '/Customer',
        name: 'Customer',
        component: Customer //客户
    }, {
        path: '/register',
        name: 'register',
        component: register //到访登记
    }, {
        path: '/addCus',
        name: 'addCus',
        component: addCus //新建用户
    }, {
        path: '/editCus/:id',
        name: 'editCus',
        component: editCus //新建用户
    }, {
        path: '/Visit/:id',
        name: 'Visit',
        component: Visit //回访
    }]
})

// router.beforeEach((to, from, next) => {
//     if (to.matched.length ===0) {                                        //如果未匹配到路由
//       from.name ? next({ name:from.name }) : next('/');   //如果上级也未匹配到路由则跳转登录页面，如果上级能匹配到则转上级路由
//     } else {
//       next();                                                                            //如果匹配到正确跳转
//     }
//   });